// 统一封装api接口
const https = "https://tea.qingnian8.com/api/bizhi";

export function request(config = {}) {
  let { url, data = {}, method = "GET", header = {} } = config
  url = https + url;

  return new Promise((resolve, reject) => {
    uni.request({
      url,
      method,
      data,
      header: {
        "access-key": "yeer1234@"
      },
      success: res => {
        if (res.data.errCode === 0) {
          resolve(res)
        } else if (res.data.errCode === 400) {
          uni.showModal({
            title: "错误提示",
            content: res.data.errMsg || "未知错误",
            showCancel: false
          })
          reject(res.data)
        } else {
          uni.showToast({
            title: res.data.errMsg,
            icon: 'none'
          })
          reject(res.data)
        }

      },
      fail: err => {
        reject(err)
      }
    })
  })
}